package com.han.iterator;

import java.util.List;

/**
 * @ClassName StudentIteratorImpl
 * @Description 具体迭代器角色类
 * @Author duoduo Han
 * @Date 2024/6/20 10:54
 */
public class StudentIteratorImpl implements Iterator<Student> {
    private List<Student> list;
    private int position = 0;//记录遍历时的位置

    public StudentIteratorImpl(List<Student> list) {
        this.list = list;
    }

    @Override
    public boolean hasNext() {
        return position < list.size();
    }

    @Override
    public Student next() {
        //获取当前位置的元素
        Student curentStudent = list.get(position);
        position++;
        return curentStudent;
    }
}
